package com.teaphy.coroutinecrawler.flow

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect

fun main() = runBlocking {
    val job = launch {
        val value = "A"
        val mutableStateFlow = MutableStateFlow(value)

        val listSource = listOf<String>("B", "C", "D")

        listSource.forEach {
            mutableStateFlow.emit(it)
            delay(100)
        }

        mutableStateFlow.collect {
            println("MutableStateFlow 接收数据：$it")
        }
    }

    launch {
        delay(3000)
        job.cancel()
    }

    println("Done")
}